#include "output.h"
#include <iomanip>

void output_file_md() {
    std::ofstream outfile;
    outfile.open("..\\result\\energy_results.csv"); // Can be opened with MS EXCEL.
    outfile << "Time(fs), T(K),  Pressure(bar), Ep(kJ/mol), Ek(kJ/mol), Etotal(kJ/mol)" << endl;
    for (int i = 0; i < Parameter_Nwrite_physical_properties; i++) {
        outfile << timeVec[i] << "," << temperatureVec[i] << "," << pressureVec[i] << "," << EpVec[i] << "," << EkVec[i] << "," << EtotalVec[i] << endl;
    }

    outfile.close();
}

void output_file_acf(std::vector<double> acf){
    ofstream outfile;
    outfile.open("..\\result\\acf_results.csv");
    outfile << "Time(fs), Cvv(t)" << endl;
    for (int i = 0; i < Parameter_Nsteps; i++) {
        //file << acf[i] * 2.089425786e13 << endl;
        outfile << timeVec[i] << "," << acf[i] / acf[0] << endl;
    }
}

void output_file_initial_coord(vector<Atom>mol) {
    ofstream file;
    file.open("..\\result\\initial_coord.xyz");
    file << Parameter_Natoms << endl;
    file << "coord after initialized" << endl;
    for (int i = 0; i < Parameter_Natoms; i++) {
        file << left << setw(16) << "Ar" << left << setw(16) << mol[i].coord[0] << left << setw(16) << mol[i].coord[1] << left << setw(16) << mol[i].coord[2] << endl;
    }
}

void output_file_initial_coord_PIMD() {
    ofstream file;
    file.open("..\\result\\initial_coord.xyz");
    file << Parameter_Natoms << endl;
    file << "coord after initialized" << endl;

    for (int k = 0; k < Parameter_nbeads; k++) {
        file << "bead = " << '\t' << k + 1 << endl;
        for (int i = 0; i < Parameter_Natoms; i++) {
            file << left << setw(16) << "Ar" << left << setw(16) << mirror[k][i].coord[0] << left << setw(16) << mirror[k][i].coord[1] << left << setw(16) << mirror[k][i].coord[2] << endl;
        }
    }

}

void output_file_initial_coord_PIMD_transform() {
    ofstream file;
    file.open("..\\result\\initial_coord.xyz");
    file << Parameter_Natoms << endl;
    file << "coord after initialized" << endl;

    for (int k = 0; k < Parameter_nbeads; k++) {
        file << "bead = " << '\t' << k + 1 << endl;
        for (int i = 0; i < Parameter_Natoms; i++) {
            file << left << setw(16) << "Ar" << left << setw(16) << staging_mirror[k][i].coord[0] << left << setw(16) << staging_mirror[k][i].coord[1] << left << setw(16) << staging_mirror[k][i].coord[2] << endl;
        }
    }

}



void output_file_coord_PIMD(vector<Atom>mol) {
    ofstream file;
    file.open("..\\result\\initial_coord.xyz");
    file << Parameter_Natoms << endl;
    file << "coord after initialized" << endl;
    for (int step = 0; step < 3; step++) {
        file << "step = " << '\t' << step + 1 << endl;
        for (int k = 0; k < Parameter_nbeads; k++) {
            file << "bead = " << '\t' << k + 1 << endl;
            for (int i = 0; i < Parameter_Natoms; i++) {
                file << left << setw(16) << "Ar" << left << setw(16) << staging_mirror[k][i].coord[0] << left << setw(16) << staging_mirror[k][i].coord[1] << left << setw(16) << staging_mirror[k][i].coord[2] << endl;
            }
        }
    }
}


void output_file_PIMD_Hamilton() {
    ofstream outfile;
    outfile.open("..\\result\\hamiltonion_results.csv"); // Can be opened with MS EXCEL.
    outfile << "Time(fs), T(k), Hamilton(KJ/mol), Ek(kJ/mol), Espr(kJ/mol), Ep(kJ/mol)" << endl;

    for (int i = 0; i < Parameter_Nwrite_physical_properties; i++) {
        outfile << timeVec[i] << "," << temperaturePIMD_staging[0][i] << ',' << Hamiltonian_staging[i] << "," << EkPIMD_staging[i] << "," << EsprPIMD_staging[i] << ',' << EpPIMD_staging[i] << endl;
    }
    outfile.close();
}
